package net.shop.biz.service.impl;

import org.springframework.stereotype.Service;

import ths.core.system.Unsigned;

import net.shop.biz.service.FriendlyUrlService;
import net.shop.dal.entity.Product;
import net.shop.dal.entity.ProductVirtualCategory;

@Service
public class FriendlyUrlServiceImpl implements FriendlyUrlService {

	public String getActionUrl(String path, String name) {
		return path +"/"+ name + ".htm";
	}

	public long getUrlHaseCode(String url) {
		return Unsigned.getUnsignedInt(url.hashCode());
	}
	
	public String getProductVirtualCategoryUrl(ProductVirtualCategory parent, ProductVirtualCategory currently) {
		// /product/category/computers-tablets/pc-laptops.html
		StringBuffer bf = new StringBuffer("/product/category/");
		bf.append(parent.getFriendlyUrl()).append('/');
		bf.append(currently.getFriendlyUrl()).append(".html");
		return bf.toString();
	}

	public String getProductUrl(ProductVirtualCategory parent, Product product) {
		// /products/pc-laptops/pan-android2-2-smartphone-w-3-2-inch-touchscreen-dual-sim-tv-wifi-gps.html
		StringBuffer bf = new StringBuffer("/products/");
		bf.append(parent.getFriendlyUrl()).append('/');
		bf.append(product.getFriendlyUrl()).append(".html");
		return bf.toString();
	}
}
